Amarkal.settings.fields.unflagAll   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
Amarkal.settings.fields = {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
2
    $form: null,
3
    $fields: null,
4
    init: function () {
5
        this.$form = $('#amarkal-settings-form');
6
        this.$fields = this.$form.find('.amarkal-settings-field');
7
8
        var _this = this;
9
        $('.amarkal-ui-component').on('amarkal.change',function(e, component){
10
            if($(this).amarkalUIComponent('changed')) {
11
                Amarkal.settings.fields.flag('notice', component.props.name);
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
12
                Amarkal.settings.sections.flag('notice', component.props.section);
13
                Amarkal.settings.notifier.notice("Settings have changed, click \"Save\" to apply them.");
14
            }
15
            else {
16
                Amarkal.settings.fields.unflag('notice', component.props.name);
17
            }
18
            
19
            if(!Amarkal.settings.sections.changed(component.props.section)) {
20
                Amarkal.settings.sections.unflag('notice', component.props.section);
21
            }
22
23
            if(!_this.$form.amarkalUIForm('changed')) {
24
                Amarkal.settings.notifier.clearNotifications();
25
            }
26
        }).on('amarkal.hide', function(){
27
            Amarkal.settings.fields.hide($(this).parents('.amarkal-settings-field'));
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
28
        }).on('amarkal.show', function(){
29
            if($(this).parents('.amarkal-settings-field').attr('data-section') === Amarkal.settings.sections.activeSection) {
0 ignored issues
show
Bug introduced by
The variable Amarkal seems to be never declared. If this is a global, consider adding a /** global: Amarkal */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
30
                Amarkal.settings.fields.show($(this).parents('.amarkal-settings-field'));
31
            }
32
        });
33
    },
34
    search: function(query) {
35
        var matches  = [];
36
        var $form    = this.$form;
37
        
38
        this.$fields.each(function(){
39
            var $field = $(this),
40
                name   =  $field.attr('data-name'),
41
                title  = $field.find('h3').text().toLowerCase(),
42
                help   = $field.find('.help-content').text();
43
                description = $field.find('.description').text();
0 ignored issues
show
Bug introduced by
The variable description seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.description.
Loading history...
44
45
            // Don't add fields that are currently hidden
46
            if('' !== name && !$form.amarkalUIForm('isVisible', name)) return;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
47
48
            // Check query against the field's title
49
            if(title.match(query) || description.match(query) || help.match(query)) {
50
                matches.push($field);
51
            }
52
        });
53
54
        // Convert the matches array to a jQuery object
55
        return $(matches).map(function(){return this.toArray();});
56
    },
57
    show: function($fields) {
58
        var _this = this;
59
        $fields.each(function(){
60
            var $comp = $(this).find('.amarkal-ui-component'),
61
                name  = $comp.amarkalUIComponent('getName');
62
63
            // Only show components whose visibility condition is satisfied
64
            if(!name || _this.$form.amarkalUIForm('isVisible', name)) {
65
                $(this).addClass('visible');
66
                $comp.amarkalUIComponent('refresh');
67
            }
68
        });
69
    },
70
    hide: function($fields) {
71
        $fields.removeClass('visible');
72
    },
73
    hideAll: function () {
74
        this.hide(this.$fields);
75
    },
76
    showAll: function () {
77
        this.show(this.$fields);
78
    },
79
    flag: function(type, fieldName) {
80
        this.$fields.filter('[data-name="'+fieldName+'"]').addClass('flag-'+type);
81
    },
82
    unflag: function(type, fieldName) {
83
        this.$fields.filter('[data-name="'+fieldName+'"]').removeClass('flag-'+type);
84
    },
85
    unflagAll: function() {
86
        this.$fields.removeClass('flag-error flag-notice');
87
    }
88
};